home *** CD-ROM | disk | FTP | other *** search
- /*
- this modual contains all the routines to handle the scrolling of a window.
- This routine is called from the "do mouse" modual.
- */
-
-
- #include "my color.h"
- pascal void up_action(ControlHandle, short);
- pascal void down_action(ControlHandle, short);
- pascal void page_up_action(ControlHandle, short);
- pascal void page_down_action(ControlHandle, short);
- pascal void thumb_action(void);
- RgnHandle updateRgn = 0L;
-
- Boolean do_controls(the_window, where) /* the_window is, obviously, the window that is
- active, "where" is the point where the mouse
- was clicked, in global cooridiates, inside
- the active window. do_controls() will return
- TRUE is a control was clicked in otherwise
- it will return FALSE */
- CWindowPtr the_window;
- Point where;
- {
- short part_code, new_value, which_control, old_value;
- short scroll_amount;
- ControlHandle the_control;
- CWindowPtr owner_window;
- Rect window_rect, draw_rect;
- CGrafPtr the_tiff_picture;
- short which_control_min, which_control_max;
-
-
- if(!updateRgn)
- updateRgn = NewRgn();
- else
- SetEmptyRgn(updateRgn); /* allow the update region to accumulate into this region */
-
- GlobalToLocal(&where); /* first convert the mouse location to local coordinates */
- part_code = FindControl(where, the_window, &the_control); /* now find out what part
- of the window was clicked in */
- if(!part_code) return FALSE; /* if part_code is NULL, then the scroll bars
- were not clicked in */
- switch(part_code)
- {
- case inUpButton: /* the user clicked in the UP arrow of the scroll bar */
- TrackControl(the_control, where, up_action);
- break;
-
- case inDownButton: /* the user clicked in the DOWN arrow of the scroll bar */
- TrackControl(the_control, where, down_action);
- break;
-
- case inPageUp: /* the user is clicking in the page up region of the scroll bar */
- TrackControl(the_control, where, page_up_action);
- break;
-
- case inPageDown: /* the user is clicking in the page down region of the scroll bar */
- TrackControl(the_control, where, page_down_action);
- break;
-
- case inThumb: /* the user is draging the "thumb" around */
- old_value = GetCtlValue(the_control); /* this is the last value the control had before the current activity */
- TrackControl(the_control, where, thumb_action);
- new_value = GetCtlValue(the_control); /* this is the last value the control had before the current activity */
- owner_window = (CWindowPtr)(**the_control).contrlOwner; /* I refere to the control's owning window so that I can easily get to the text edit record */
- scroll_amount = new_value - old_value;
- which_control = GetCRefCon(the_control); /* this is the control that was clicked in */
- which_control_min = GetCtlMin(the_control);
- which_control_max = GetCtlMax(the_control);
- window_rect = owner_window->portRect;
- window_rect.bottom -= BAR_WIDTH;
- window_rect.right -= BAR_WIDTH;
- the_tiff_picture = (CGrafPtr)GetWRefCon(owner_window);
- if(the_tiff_picture)
- {
- if(which_control == VERTICLE_SCROLL) /* if we're in the verticle scroll bar move the text down */
- {
- (*the_tiff_picture).portRect.top += scroll_amount;
- (*the_tiff_picture).portRect.bottom =
- (*the_tiff_picture).portRect.top +
- ((*owner_window).portRect.bottom -
- (*owner_window).portRect.top) - BAR_WIDTH;
- if( (*the_tiff_picture).portRect.bottom >
- (**(*the_tiff_picture).portPixMap).bounds.bottom)
- (*the_tiff_picture).portRect.bottom =
- (**(*the_tiff_picture).portPixMap).bounds.bottom;
- ScrollRect(&window_rect, 0, -scroll_amount, updateRgn);
- draw_rect = owner_window->portRect;
- draw_rect.bottom = draw_rect.top +
- ((*the_tiff_picture).portRect.bottom -
- (*the_tiff_picture).portRect.top);
- draw_rect.right = draw_rect.left +
- ((*the_tiff_picture).portRect.right -
- (*the_tiff_picture).portRect.left);
- HLock((*the_tiff_picture).portPixMap);
- HLock((*owner_window).portPixMap);
- CopyBits( *(*the_tiff_picture).portPixMap,
- *(*owner_window).portPixMap,
- &(*the_tiff_picture).portRect,
- &draw_rect,
- srcCopy, 0L);
- HUnlock((*owner_window).portPixMap);
- HUnlock((*the_tiff_picture).portPixMap);
- ValidRgn(updateRgn);
- }
- else if (which_control == HORIZONTAL_SCROLL) /* if we're in the horizontal scroll bar move the text to the left */
- {
- (*the_tiff_picture).portRect.left += scroll_amount; /* allow for the scroll bars when scrolling */
- (*the_tiff_picture).portRect.right =
- (*the_tiff_picture).portRect.left +
- ((*owner_window).portRect.right -
- (*owner_window).portRect.left) - BAR_WIDTH;
- if( (*the_tiff_picture).portRect.right >
- (**(*the_tiff_picture).portPixMap).bounds.right)
- (*the_tiff_picture).portRect.right =
- (**(*the_tiff_picture).portPixMap).bounds.right;
- ScrollRect(&window_rect, -scroll_amount, 0, updateRgn);
- draw_rect = owner_window->portRect; /* define the destination rectangle for the PixMap */
- draw_rect.bottom = draw_rect.top +
- ((*the_tiff_picture).portRect.bottom -
- (*the_tiff_picture).portRect.top);
- draw_rect.right = draw_rect.left +
- ((*the_tiff_picture).portRect.right -
- (*the_tiff_picture).portRect.left);
- HLock((*the_tiff_picture).portPixMap);
- HLock((*owner_window).portPixMap);
- CopyBits( *(*the_tiff_picture).portPixMap,
- *(*owner_window).portPixMap,
- &(*the_tiff_picture).portRect,
- &draw_rect,
- srcCopy, 0L);
- HUnlock((*owner_window).portPixMap);
- HUnlock((*the_tiff_picture).portPixMap);
- ValidRgn(updateRgn);
- }
- }
- break;
-
- default: /* default to a SysBeep 'cause that will mean something is wrong */
- SysBeep(11);
- }
- return TRUE; /* TRUE means I successfully handled the controls */
- }
-
-
- pascal void up_action(control, part) /* TrackControl will repeatedly call this
- routine as long as the mouse is held down
- in the UP arrow of the scroll bar */
- ControlHandle control;
- short part;
- {
- short old_control_value, scroll_units, control_min_value, new_control_value;
- CWindowPtr owner_window;
- short which_control;
- CGrafPtr the_tiff_picture;
- Rect window_rect, draw_rect;
-
- scroll_units = 3; /* this is how many pixels I'll scroll the window */
- which_control = GetCRefCon(control); /* this is the control that was clicked in */
- old_control_value = GetCtlValue(control); /* this is the last value the control had before the current activity */
- control_min_value = GetCtlMin(control); /* this is the minimum value the control can have, this was defined when the control was created */
- new_control_value = old_control_value - scroll_units; /* this is the new value that the control will have after the scrolling */
- if(new_control_value < control_min_value) /* if the new control value isn't legitimate */
- SetCtlValue(control, control_min_value);/* just set the control to the minimum value */
- else /* else, set the control value to the new value, the scroll the text */
- {
- SetCtlValue(control, new_control_value);
- owner_window = (CWindowPtr)(**control).contrlOwner; /* I refere to the control's owning window so that I can easily get to the text edit record */
- window_rect = owner_window->portRect;
- window_rect.bottom -= BAR_WIDTH;
- window_rect.right -= BAR_WIDTH;
- the_tiff_picture = (CGrafPtr)GetWRefCon(owner_window);
- if(the_tiff_picture)
- {
- if(which_control == VERTICLE_SCROLL) /* if we're in the verticle scroll bar move the text down */
- {
- (*the_tiff_picture).portRect.top -= scroll_units;
- (*the_tiff_picture).portRect.bottom = (*the_tiff_picture).portRect.top +
- ((*owner_window).portRect.bottom -
- (*owner_window).portRect.top) -
- BAR_WIDTH;
- if( (*the_tiff_picture).portRect.bottom >
- (**(*the_tiff_picture).portPixMap).bounds.bottom)
- (*the_tiff_picture).portRect.bottom =
- (**(*the_tiff_picture).portPixMap).bounds.bottom;
- ScrollRect(&window_rect, 0, scroll_units, updateRgn);
- draw_rect = owner_window->portRect; /* define the destination rectangle for the PixMap */
- draw_rect.bottom = draw_rect.top +
- ((*the_tiff_picture).portRect.bottom -
- (*the_tiff_picture).portRect.top);
- draw_rect.right = draw_rect.left +
- ((*the_tiff_picture).portRect.right -
- (*the_tiff_picture).portRect.left);
- HLock((*the_tiff_picture).portPixMap);
- HLock((*owner_window).portPixMap);
- CopyBits( *(*the_tiff_picture).portPixMap,
- *(*owner_window).portPixMap,
- &(*the_tiff_picture).portRect,
- &draw_rect,
- srcCopy, 0L);
- HUnlock((*owner_window).portPixMap);
- HUnlock((*the_tiff_picture).portPixMap);
- ValidRgn(updateRgn);
- }
- else if (which_control == HORIZONTAL_SCROLL) /* if we're in the horizontal scroll bar move the text to the left */
- {
- (*the_tiff_picture).portRect.left -= scroll_units;/* allow for the scroll bars when scrolling */
- (*the_tiff_picture).portRect.right = (*the_tiff_picture).portRect.left +
- ((*owner_window).portRect.right -
- (*owner_window).portRect.left) -
- BAR_WIDTH;
- if( (*the_tiff_picture).portRect.right >
- (**(*the_tiff_picture).portPixMap).bounds.right)
- (*the_tiff_picture).portRect.right =
- (**(*the_tiff_picture).portPixMap).bounds.right;
- ScrollRect(&window_rect, scroll_units, 0, updateRgn);
- draw_rect = owner_window->portRect; /* define the destination rectangle for the PixMap */
- draw_rect.bottom = draw_rect.top +
- ((*the_tiff_picture).portRect.bottom -
- (*the_tiff_picture).portRect.top);
- draw_rect.right = draw_rect.left +
- ((*the_tiff_picture).portRect.right -
- (*the_tiff_picture).portRect.left);
- HLock((*the_tiff_picture).portPixMap);
- HLock((*owner_window).portPixMap);
- CopyBits( *(*the_tiff_picture).portPixMap,
- *(*owner_window).portPixMap,
- &(*the_tiff_picture).portRect,
- &draw_rect,
- srcCopy, 0L);
- HUnlock((*owner_window).portPixMap);
- HUnlock((*the_tiff_picture).portPixMap);
- ValidRgn(updateRgn);
- }
- }
- }
- }
-
- pascal void down_action(control, part)/* TrackControl will call this routine
- repeatedly as long as the mouse is held
- down in the DOWN arrow */
- ControlHandle control;
- short part;
- {
- short old_control_value, scroll_units, control_max_value, new_control_value;
- CWindowPtr owner_window;
- short which_control;
- CGrafPtr the_tiff_picture;
- Rect window_rect, draw_rect;
-
- scroll_units = 3; /* this is the number of pixels I'll scroll each time the routine is called */
- which_control = GetCRefCon(control); /* this is the control the mouse was pressed in */
- old_control_value = GetCtlValue(control); /* this is the value the controll had when it was last used */
- control_max_value = GetCtlMax(control); /* this is the maximum value the control can obtain, this was set when the control was defined */
- new_control_value = old_control_value + scroll_units; /* this is the value the control will be set to when we are done */
- if(new_control_value > control_max_value) /* if the new control value too large then just set the control to the maximum value */
- SetCtlValue(control, control_max_value);
- else /* else set the controll to the new value and scroll the test */
- {
- SetCtlValue(control, new_control_value);
- owner_window = (CWindowPtr)(**control).contrlOwner; /* I refere to the control's owning window so that I can easily get to the text edit record */
- window_rect = owner_window->portRect;
- window_rect.bottom -= BAR_WIDTH;
- window_rect.right -= BAR_WIDTH;
- the_tiff_picture = (CGrafPtr)GetWRefCon(owner_window);
- if(the_tiff_picture)
- {
- if(which_control == VERTICLE_SCROLL) /* if we're in the verticle scroll bar move the text down */
- {
- (*the_tiff_picture).portRect.top += scroll_units;
- (*the_tiff_picture).portRect.bottom = (*the_tiff_picture).portRect.top +
- ((*owner_window).portRect.bottom -
- (*owner_window).portRect.top) -
- BAR_WIDTH;
- if( (*the_tiff_picture).portRect.bottom >
- (**(*the_tiff_picture).portPixMap).bounds.bottom)
- (*the_tiff_picture).portRect.bottom =
- (**(*the_tiff_picture).portPixMap).bounds.bottom;
- ScrollRect(&window_rect, 0, -scroll_units, updateRgn);
- draw_rect = owner_window->portRect; /* define the destination rectangle for the PixMap */
- draw_rect.bottom = draw_rect.top +
- ((*the_tiff_picture).portRect.bottom -
- (*the_tiff_picture).portRect.top);
- draw_rect.right = draw_rect.left +
- ((*the_tiff_picture).portRect.right -
- (*the_tiff_picture).portRect.left);
- HLock((*the_tiff_picture).portPixMap);
- HLock((*owner_window).portPixMap);
- CopyBits( *(*the_tiff_picture).portPixMap,
- *(*owner_window).portPixMap,
- &(*the_tiff_picture).portRect,
- &draw_rect,
- srcCopy, 0L);
- HUnlock((*owner_window).portPixMap);
- HUnlock((*the_tiff_picture).portPixMap);
- ValidRgn(updateRgn);
- }
- else if (which_control == HORIZONTAL_SCROLL) /* if we're in the horizontal scroll bar move the text to the left */
- {
- (*the_tiff_picture).portRect.left += scroll_units;/* allow for the scroll bars when scrolling */
- (*the_tiff_picture).portRect.right = (*the_tiff_picture).portRect.left +
- ((*owner_window).portRect.right -
- (*owner_window).portRect.left) -
- BAR_WIDTH;
- if( (*the_tiff_picture).portRect.right >
- (**(*the_tiff_picture).portPixMap).bounds.right)
- (*the_tiff_picture).portRect.right =
- (**(*the_tiff_picture).portPixMap).bounds.right;
- ScrollRect(&window_rect, -scroll_units, 0, updateRgn);
- draw_rect = owner_window->portRect; /* define the destination rectangle for the PixMap */
- draw_rect.bottom = draw_rect.top +
- ((*the_tiff_picture).portRect.bottom -
- (*the_tiff_picture).portRect.top);
- draw_rect.right = draw_rect.left +
- ((*the_tiff_picture).portRect.right -
- (*the_tiff_picture).portRect.left);
- HLock((*the_tiff_picture).portPixMap);
- HLock((*owner_window).portPixMap);
- CopyBits( *(*the_tiff_picture).portPixMap,
- *(*owner_window).portPixMap,
- &(*the_tiff_picture).portRect,
- &draw_rect,
- srcCopy, 0L);
- HUnlock((*owner_window).portPixMap);
- HUnlock((*the_tiff_picture).portPixMap);
- ValidRgn(updateRgn);
- }
- }
- }
- }
-
- pascal void page_up_action(control, part) /* TrackControl will repeatedly call this
- routine as long as the mouse is held down
- in the PageUp region of the scroll bar */
- ControlHandle control;
- short part;
- {
- short old_control_value, scroll_units, control_min_value, new_control_value;
- CWindowPtr owner_window;
- short which_control;
- CGrafPtr the_tiff_picture;
- Rect window_rect, draw_rect;
-
- scroll_units = 10; /* this is the number of pixels I'll scroll each time this routine is called */
- which_control = GetCRefCon(control);
- old_control_value = GetCtlValue(control); /* this is the value of the scroll bar from the last time it was used */
- control_min_value = GetCtlMin(control); /* this is the minimum value the scroll bar can obtain, this was set when the scroll bar was defined */
- new_control_value = old_control_value - scroll_units; /* this is the new value for the control */
- if(new_control_value < control_min_value) scroll_units = old_control_value - control_min_value;
- if(old_control_value <= control_min_value) /* if the new value is too small, just set the control to the minimum value */
- SetCtlValue(control, control_min_value);
- else /* if everything is O.K., set the control to the new value, and scroll the window */
- {
- SetCtlValue(control, old_control_value - scroll_units);
- owner_window = (CWindowPtr)(**control).contrlOwner; /* I refer to the control's owning window so that I can easily get to the text edit record */
- window_rect = owner_window->portRect;
- window_rect.bottom -= BAR_WIDTH;
- window_rect.right -= BAR_WIDTH;
- the_tiff_picture = (CGrafPtr)GetWRefCon(owner_window);
- if(the_tiff_picture)
- {
- if(which_control == VERTICLE_SCROLL) /* if we're in the verticle scroll bar move the text down */
- {
- (*the_tiff_picture).portRect.top -= scroll_units;
- (*the_tiff_picture).portRect.bottom = (*the_tiff_picture).portRect.top +
- ((*owner_window).portRect.bottom -
- (*owner_window).portRect.top) -
- BAR_WIDTH;
- if( (*the_tiff_picture).portRect.bottom >
- (**(*the_tiff_picture).portPixMap).bounds.bottom)
- (*the_tiff_picture).portRect.bottom =
- (**(*the_tiff_picture).portPixMap).bounds.bottom;
- ScrollRect(&window_rect, 0, scroll_units, updateRgn);
- draw_rect = owner_window->portRect; /* define the destination rectangle for the PixMap */
- draw_rect.bottom = draw_rect.top +
- ((*the_tiff_picture).portRect.bottom -
- (*the_tiff_picture).portRect.top);
- draw_rect.right = draw_rect.left +
- ((*the_tiff_picture).portRect.right -
- (*the_tiff_picture).portRect.left);
- HLock((*the_tiff_picture).portPixMap);
- HLock((*owner_window).portPixMap);
- CopyBits( *(*the_tiff_picture).portPixMap,
- *(*owner_window).portPixMap,
- &(*the_tiff_picture).portRect,
- &draw_rect,
- srcCopy, 0L);
- HUnlock((*owner_window).portPixMap);
- HUnlock((*the_tiff_picture).portPixMap);
- ValidRgn(updateRgn);
- }
- else if (which_control == HORIZONTAL_SCROLL) /* if we're in the horizontal scroll bar move the text to the left */
- {
- (*the_tiff_picture).portRect.left -= scroll_units;
- (*the_tiff_picture).portRect.right = (*the_tiff_picture).portRect.left +
- ((*owner_window).portRect.right -
- (*owner_window).portRect.left) -
- BAR_WIDTH;
- if( (*the_tiff_picture).portRect.right >
- (**(*the_tiff_picture).portPixMap).bounds.right)
- (*the_tiff_picture).portRect.right =
- (**(*the_tiff_picture).portPixMap).bounds.right;
- ScrollRect(&window_rect, scroll_units, 0, updateRgn);
- draw_rect = owner_window->portRect; /* define the destination rectangle for the PixMap */
- draw_rect.bottom = draw_rect.top +
- ((*the_tiff_picture).portRect.bottom -
- (*the_tiff_picture).portRect.top);
- draw_rect.right = draw_rect.left +
- ((*the_tiff_picture).portRect.right -
- (*the_tiff_picture).portRect.left);
- HLock((*the_tiff_picture).portPixMap);
- HLock((*owner_window).portPixMap);
- CopyBits( *(*the_tiff_picture).portPixMap,
- *(*owner_window).portPixMap,
- &(*the_tiff_picture).portRect,
- &draw_rect,
- srcCopy, 0L);
- HUnlock((*owner_window).portPixMap);
- HUnlock((*the_tiff_picture).portPixMap);
- ValidRgn(updateRgn);
- }
- }
- }
- }
-
- pascal void page_down_action(control, part) /* TrackControl will repeatedly call this
- routine as long as the mouse is held down
- in the PageDown region of the scroll bar */
- ControlHandle control;
- short part;
- {
- short old_control_value, scroll_units, control_max_value, new_control_value;
- CWindowPtr owner_window;
- short which_control;
- CGrafPtr the_tiff_picture;
- Rect window_rect, draw_rect;
-
- scroll_units = 10; /* this is the amount I'll scroll each time this routine is acalled */
- which_control = GetCRefCon(control); /* this is the ID of scroll bar that was choosen */
- old_control_value = GetCtlValue(control); /* this is the value of the scroll bar from the last time it was used */
- control_max_value = GetCtlMax(control); /* this is the maximum value the scroll bar can obtain */
- new_control_value = old_control_value + scroll_units; /* this is the new value for the scroll bar */
- if(new_control_value > control_max_value) scroll_units = control_max_value - old_control_value;
- if(old_control_value >= control_max_value) /* if the new value is too large, then just set the control to the maximum value and leave */
- SetCtlValue(control, control_max_value);
- else /* else set the control to the new value, and the scroll the window */
- {
- SetCtlValue(control, new_control_value);
- owner_window = (CWindowPtr)(**control).contrlOwner; /* I refere to the control's owning window so that I can easily get to the text edit record */
- window_rect = owner_window->portRect;
- window_rect.bottom -= BAR_WIDTH;/* allow for the scroll bars when scrolling */
- window_rect.right -= BAR_WIDTH;
- the_tiff_picture = (CGrafPtr)GetWRefCon(owner_window);
- if(the_tiff_picture)
- {
- if(which_control == VERTICLE_SCROLL) /* if we're in the verticle scroll bar move the text down */
- {
- (*the_tiff_picture).portRect.top += scroll_units;
- (*the_tiff_picture).portRect.bottom = (*the_tiff_picture).portRect.top +
- ((*owner_window).portRect.bottom -
- (*owner_window).portRect.top) -
- BAR_WIDTH;
- if( (*the_tiff_picture).portRect.bottom >
- (**(*the_tiff_picture).portPixMap).bounds.bottom)
- (*the_tiff_picture).portRect.bottom =
- (**(*the_tiff_picture).portPixMap).bounds.bottom;
- ScrollRect(&window_rect, 0, -scroll_units, updateRgn);
- draw_rect = owner_window->portRect; /* define the destination rectangle for the PixMap */
- draw_rect.bottom = draw_rect.top +
- ((*the_tiff_picture).portRect.bottom -
- (*the_tiff_picture).portRect.top);
- draw_rect.right = draw_rect.left +
- ((*the_tiff_picture).portRect.right -
- (*the_tiff_picture).portRect.left);
- HLock((*the_tiff_picture).portPixMap);
- HLock((*owner_window).portPixMap);
- CopyBits( *(*the_tiff_picture).portPixMap,
- *(*owner_window).portPixMap,
- &(*the_tiff_picture).portRect,
- &draw_rect,
- srcCopy, 0L);
- HUnlock((*owner_window).portPixMap);
- HUnlock((*the_tiff_picture).portPixMap);
- ValidRgn(updateRgn);
- }
- else if (which_control == HORIZONTAL_SCROLL) /* if we're in the horizontal scroll bar move the text to the left */
- {
- (*the_tiff_picture).portRect.left += scroll_units;
- (*the_tiff_picture).portRect.right = (*the_tiff_picture).portRect.left +
- ((*owner_window).portRect.right -
- (*owner_window).portRect.left) -
- BAR_WIDTH;
- if( (*the_tiff_picture).portRect.right >
- (**(*the_tiff_picture).portPixMap).bounds.right)
- (*the_tiff_picture).portRect.right =
- (**(*the_tiff_picture).portPixMap).bounds.right;
- ScrollRect(&window_rect, -scroll_units, 0, updateRgn);
- draw_rect = owner_window->portRect; /* define the destination rectangle for the PixMap */
- draw_rect.bottom = draw_rect.top +
- ((*the_tiff_picture).portRect.bottom -
- (*the_tiff_picture).portRect.top);
- draw_rect.right = draw_rect.left +
- ((*the_tiff_picture).portRect.right -
- (*the_tiff_picture).portRect.left);
- HLock((*the_tiff_picture).portPixMap);
- HLock((*owner_window).portPixMap);
- CopyBits( *(*the_tiff_picture).portPixMap,
- *(*owner_window).portPixMap,
- &(*the_tiff_picture).portRect,
- &draw_rect,
- srcCopy, 0L);
- HUnlock((*owner_window).portPixMap);
- HUnlock((*the_tiff_picture).portPixMap);
- ValidRgn(updateRgn);
- }
- }
- }
- }
-
- pascal void thumb_action() /* I just put this here as an example, I don't have
- anything to do while the user is draging the
- "thumb" around, note that TrackControl does not
- pass any parameters along to this routine, so
- you must allow for global variables if you want
- to do anything "Neat" to the window */
- {
- return;
- }
-
-